<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/icons.css" />
    <script src="../script/jquery-1.9.1.min.js"></script>
    <script src="../script/bootstrap.min.js"></script>
    <style>
        .table tr:first-child {
            background: url(static/img/tableheader-bg.gif) no-repeat left top;
            background-color: #DCE9F2;
            border-top: 1px solid #CBD6DE;
            border-bottom: 1px solid #ADBECB;
            color: #467aa7;
            font-size: 13px;
            font-weight: bold;
        }

        .table {
            margin-bottom: 15px;
            border-collapse: collapse;
            font-size: 13px;
            margin-bottom: 15px;
            width: 2000%;
            border-collapse: collapse;
        }

        .table td {
            height: 40px;
            text-align: center;
            border: 1px solid #CBD6DE;
            padding: 0;
            margin: 0;
            vertical-align: middle !important;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            产品检测单
        </div>
    </header>
    <div class="aui-content" style="margin-top:50px;">

        <div class="aui-form">

            <div class="aui-content aui-margin-b-15">
                <ul class="aui-list aui-form-list" style="font-size: 14px;">
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">序列号</div>
                            <div class="aui-list-item-input">
                                <input type="text" placeholder="扫描 序列号" id="serialNo" onclick="getIdSelector();" />
                            </div>

                        </div>
                    </li>
                    <!--  <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">工序</div>
                            <select id="opCode" onchange="getChkTemplate()">
                            </select>
                        </div>
                    </li> -->
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">检测模板</div>
                            <div class="aui-list-item-input">
                                <input type="text" placeholder="检测模板" id="chkTemplateCode" readonly="true" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">模板名称</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="chkTemplateName" disabled="true">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">检测类型</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="chkTypeName" disabled="true">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">物料号</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="mrlCode" disabled="true">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">物料名</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="mrlName" disabled="true">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">检测数量</div>
                            <div class="aui-list-item-input">
                                <input type="number" id="qty">
                            </div>
                        </div>
                    </li>

                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">产 线</div>
                            <select id="workCenterCode">
                            </select>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="font-size: 14px;">执行状态</div>
                            <div class="aui-list-item-input">
                                <select id="zxState" style="font-size: 14px;">
                                    <option value="0" selected="true">未处理</option>
                                    <option value="3">处理中</option>
                                    <option value="7">已处理</option>
                                    <option value="8">已确认</option>
                                    <option value="9">已取消</option>
                                </select>
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="font-size: 14px;">执行结果</div>
                            <div class="aui-list-item-input">
                                <select id="zxResult" style="font-size: 14px;">
                                    <option value="0">未判定</option>
                                    <option value="1">不合格</option>
                                    <option value="5">放行</option>
                                    <option value="7">合格</option>
                                </select>
                            </div>
                        </div>
                    </li>

                </ul>
            </div>

            <!-- <ul id="myTab" class="nav nav-tabs" style="background-color: #F4F4F4;font-size: 13px;">

                </ul> -->

            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade in active" id="item">
                    <div
                        style="background-color:white; width: 100%;margin-top:2%;white-space: nowrap;overflow-x: auto;-webkit-overflow-scrolling:touch;">

                        <table class="table" style='width:100%;' id="table1">
                            <tbody style="display:block">

                            </tbody>
                        </table>
                        <table class="table" style='width:100%;' id="table">
                            <tbody id="chkItemTableHead" style="display: block;overflow-y: scroll;">

                            </tbody>
                        </table>
                    </div>
                    <div style="background-color:white; height: 100%;width: 100%;">

                        <div class="aui-content">
                            <div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
                                <p>
                                </p>
                                <div class="aui-btn aui-btn-info" onclick="doSave()" style="width: 100%;height: 100%;">
                                    <span class="aui-iconfont" style="font-size: 20px;">提交数据</span>

                                </div>
                                <p></p>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div style="background-color:white; height: 300px;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none"
                id="tableDiv">
                <table style='width:100%; font-size:14px;'>
                    <tbody>
                        <tr>
                            <td style="width:23%;text-align:right;">检&nbsp&nbsp测&nbsp单&nbsp号:</td>
                            <td id="chkBillCodeT"></td>
                        </tr>
                        <tr>
                            <td style="width:23%;text-align:right;">返&nbsp&nbsp回&nbsp标&nbsp识:</td>
                            <td id="returnType"></td>
                        </tr>
                    </tbody>
                </table>
            </div>

        </div>
    </div>

    <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    var name = "";

    var taskId = "";
    var taskCode = "";
    var itemIds = "";
    var itemCodes = "";
    var itemNames = "";
    var itemModes = "";
    var itemValues = "";
    var itemMaxValues = "";
    var itemMinValues = "";
    var itemStandardValue = "";
    var itemControlType = "";
    var josnList = [];
    var str = "";
    var mrlName = "";//物料名称
    var mrlGid = "";//物料id


    var chkType = ""; //检测单类型
    var mrlCode = ""; //物料编码
    //光标所在id
    var idSelector = "";

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
    }
    apiready = function () {
        $("#serialNo").select();
        idSelector = "serialNo";
        //菜单参数
        var query = api.pageParam.query;
        chkType = query.chkType
        console.log(chkType)
        $("#qty").val("1");
        getChkTemplate()
    }
    //7；PDA自带扫描回车事件-设备编码
    $("#sm").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            //设备编码
            $("#sm").val(sm);
        }
    });


    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150,//扫描窗口的上边距
            width: 250,//扫描窗口的宽
            height: 250,//扫描窗口的高
            useColor: false,//是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF',//渐变起始颜色
            endColor: '#7F08C8FF',//渐变结束颜色
            animTime: 2200,//扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //console.log(JSON.stringify(ret));
            var SMequipCode = ret;
            var text = document.getElementById("sm");
            text.value = SMequipCode;

        });

    }


    function doSave() {
        if (itemIds != "") {
            //点检项表格中有数据
            setItemValues();
            //提交数据到服务端
            doSubmit();
            //save()
        } else {
            alert("无点检项信息，无法提交数据");
        }
    }

    function setItemValues() {
        var itemIdArr = itemIds.split(",");
        console.log(itemIdArr)
        var itemValue = "";
        var un = localStorage.getItem('un');
        for (i = 0; i < itemIdArr.length; i++) {
            var itemStrArr = itemIdArr[i].split(":");
            var itemCodeArr = itemCodes.split(",");
            var itemNameArr = itemNames.split(",");
            var itemMaxValueArr = itemMaxValues.split(",");
            var itemMinValueArr = itemMinValues.split(",");
            var itemControlTypeArr = itemControlType.split(",");

            var chkValue = "";
            var checkResult = "";
            var taskState = document.getElementById("zxState").value;
            var taskResult = document.getElementById("zxResult").value;
            if (itemStrArr[1] == "0") {
                //获取下拉框选中的值
                itemValue = document.getElementById(itemStrArr[0]).value;//选中的值
                checkResult = itemValue;
            }
            if (itemStrArr[1] == "1") {
                //获取文本框填的值
                itemValue = document.getElementById(itemStrArr[0]).value
                chkValue = itemValue;
                if (parseFloat(chkValue) >= parseFloat(itemMinValueArr[i]) && parseFloat(chkValue) <= parseFloat(itemMaxValueArr[i])) {
                    //检验结果 0未判定/7正常/1不合格
                    checkResult = 7;
                } else {
                    checkResult = 1;
                }
            }

            if (i == 0) {
                itemValues = itemValue;
            } else {
                itemValues = itemValues + "," + itemValue;
            }
            //将点检项的结果转化为jsonList
            var iObj = new itemObj(itemStrArr[0], itemCodeArr[i], itemNameArr[i], chkValue, checkResult, un, taskState, taskResult, itemControlTypeArr[i]);
            josnList.push(iObj);
        }
    }






    function itemObj(chkItemId, chkItemCode, chkItemName, chkValue, checkResult, chkPerson, taskState, taskResult, controlType) {
        this.chkItemGid = chkItemId;
        this.chkItemCode = chkItemCode;
        this.chkItemName = chkItemName;
        this.chkValue = chkValue;
        this.checkResult = checkResult;
        this.taskState = taskState;
        this.taskResult = taskResult;
        this.controlType = controlType;
    }



    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            if (idSelector == 'serialNo') {

                //序列号
                $("#serialNo").val(ret);
                //拆分序列号
                var arr = ret.split("#");
                //物料号
                $("#mrlCode").val(arr[1]);

                mrlCode = arr[1]
                getMrlName(mrlCode)
                //获取检测模板
                //getChkTemplate(chkType, arr[1])
                getComboxOpCode(chkType, arr[1])
                $("#tableDiv").css('display', 'none');


            }


        });
    }

    //获取检测模板
    function getMrlName(mrlCode) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMrlName";
        var data = {
            values: {
                mrlCode: mrlCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                if (map.code == "0") {
                    $("#mrlName").val(map.mrlName);

                } else {
                    api.toast({
                        msg: map.message,
                        duration: 6000
                    });
                    //物料名
                    $("#mrlName").val("");
                }
            }
        });
    }

    //获取检测模板
    function getChkTemplate() {
        var opCode = $("#opCode").val()
        console.log(mrlCode)
        console.log(chkType)
        console.log(opCode)
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkTemplateByMrlac";
        var data = {
            values: {
                chkType: chkType,
                mrlCode: mrlCode,
                opCode: opCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                if (map.code == "0") {
                    $("#chkTemplateCode").val(map.chkTemplateCode);
                    $("#chkTemplateName").val(map.chkTemplateName);
                    $("#chkTypeName").val(map.chkTypeName);
                    // $("#mrlName").val(map.mrlName);

                    var list = map.list
                    getComboxWorkCenterCode(mrlCode)
                    var html = "";
                    var html1 = "";
                    html1 += "<tr id='tr1' color: #467aa7;>";
                    html1 += "<td width='15%' algin='center'>序号</td>";
                    // html1 += "<td width='15%' algin='center'>检测项编码</td>";
                    html1 += "<td width='15%' algin='center'>检测项名称</td>";
                    // html1 += "<td width='15%' algin='center'>检测方式</td>";
                    // html1 += "<td width='15%' algin='center'>控件类型</td>";
                    html1 += "<td width='15%' algin='center'>标准值</td>";
                    html1 += "<td width='15%' algin='center'>控制上限</td>";
                    html1 += "<td width='15%' algin='center'>控制下限</td>";
                    html1 += "<td width='15%' algin='center'>检测值</td>";

                    $api.html($api.byId("chkItemTableHead"), html1);
                    str = "";
                    if (list != undefined) {
                        //遍历
                        for (var i = 0; i < list.length; i++) {
                            var itemId = list[i].sysid;
                            var itemCode = list[i].citemCode;
                            var itemName = list[i].citemName;
                            var chkMode = list[i].checkMode;
                            var controlType = list[i].controlType;
                            var standardValue = list[i].ext07 == null ? "" : list[i].ext07;
                            var maxValue = list[i].maxValue == null ? "" : list[i].maxValue;
                            var minValue = list[i].minValue == null ? "" : list[i].minValue;
                            var chkResult = '1';
                            var chkValue = "";

                            if (i == 0) {
                                itemIds = itemId + ":" + chkMode;
                                itemCodes = itemCode;
                                itemNames = itemName;
                                itemMaxValues = maxValue;
                                itemMinValues = minValue;
                                itemStandardValue = standardValue;
                                itemControlType = controlType;

                            } else {
                                itemIds = itemIds + "," + itemId + ":" + chkMode;
                                itemCodes = itemCodes + "," + itemCode;
                                itemNames = itemNames + "," + itemName;
                                itemMaxValues = itemMaxValues + "," + maxValue;
                                itemMinValues = itemMinValues + "," + minValue;
                                itemStandardValue = itemStandardValue + "," + standardValue;
                                itemControlType = itemControlType + "," + controlType;
                            }

                            if (chkMode == "0") {
                                str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox'></td><td algin='center' >"
                                    // + itemCode + "</td><td width='15%' algin='center'>"
                                    + itemName + "</td><td width='15%' algin='center'>"
                                    // + "定性" + "</td><td width='15%' algin='center'>"
                                    + standardValue + "</td><td width='15%' algin='center'>"
                                    + maxValue + "</td><td width='15%' algin='center'>"
                                    + minValue + "</td><td width='15%' algin='left'><select id='"
                                    + itemId + "'><option value='0' selected='true'>未判定</option><option value='1'>不合格</option><option value='5'>放行</option><option value='7'>合格</option></select></td></tr>"


                            }
                            if (chkMode == "1") {
                                str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox'></td><td algin='center' >"
                                    // + itemCode + "</td><td width='15%' algin='center'>"
                                    + itemName + "</td><td width='15%' algin='center'>"
                                    // + "定量" + "</td><td width='15%' algin='center'>"
                                    + standardValue + "</td><td width='15%' algin='center'>"
                                    + maxValue + "</td><td width='15%' algin='center'>"
                                    + minValue + "</td><td width='15%' algin='left'>" + "<input id='"
                                    + itemId + "' type='text' value='"

                                    + chkValue + "'></td></tr>"
                            }
                            console.log(itemMaxValues);
                            console.log(itemMinValues);
                        }
                    }
                    $("#chkItemTableHead").append(str);
                } else {
                    api.toast({
                        msg: map.message,
                        duration: 6000
                    });
                    //序列号
                    $("#serialNo").val("");
                    //物料号
                    $("#mrlCode").val("");
                }
            }
        });
    }

    //生产线下拉框
    function getComboxWorkCenterCode(mrlCode) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkcenterMrlRel";
        var data = {
            values: {
                mrlCode: mrlCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                if (list == null) {
                    api.toast({
                        msg: '物料未配置产线物料关系',
                        duration: 6000
                    });
                    return;
                } else {
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }
                    $api.html($api.byId("workCenterCode"), html);
                }

            }
        });
    }

    // //工序下拉框
    // function getComboxOpCode(chkType, mrlCode) {
    //     var un = localStorage.getItem('un');
    //     var serverUrl = localStorage.getItem('serverUrl');
    //     var url = serverUrl + "/app/getOpCodeByMrl";
    //     var data = {
    //         values: {
    //             chkType: chkType,
    //             mrlCode: mrlCode,
    //         }
    //     };
    //     api.ajax({
    //         url: url,
    //         method: 'post',
    //         dataType: 'json',
    //         timeout: 300,
    //         returnAll: false,
    //         data: data
    //     }, function (ret, err) {
    //         if (ret) {
    //             var data = JSON.stringify(ret);
    //             var map = eval("(" + data + ")");
    //             var list = eval(map.list);
    //             if (list == null) {
    //                 api.toast({
    //                     msg: '请配置模板工序',
    //                     duration: 6000
    //                 });
    //                 return;
    //             } else {
    //                 var html = "";
    //                 for (var i = 0; i < list.length; i++) {
    //                     html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
    //                 }
    //                 $api.html($api.byId("opCode"), html);
    //             }

    //         }
    //     });
    // }

    //工序下拉框
    function getComboxOpCode(chkType, mrlCode) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByMrlac";
        var data = {
            values: {
                chkType: chkType,
                mrlCode: mrlCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                if (list == null) {
                    api.toast({
                        msg: '请配置模板工序',
                        duration: 6000
                    });
                    return;
                } else {
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }
                    $api.html($api.byId("opCode"), html);
                }

            }
        });
    }


    //保存按钮
    function doSubmit() {
        //检测模板编码
        var chkTemplateCode = $("#chkTemplateCode").val();
        //物料号
        //var mrlCode = $("#mrlCode").val();
        //批次号
        var lotCode = $("#lotCode").val();
        //序列号
        var serialNo = $("#serialNo").val();
        //检测数量
        var qty = $("#qty").val();
        //产线
        var workCenterCode = $("#workCenterCode").val()


        //检测模板非空校验
        if (chkTemplateCode == "" || chkTemplateCode == null || chkTemplateCode == undefined) {
            api.toast({
                msg: '请选择检测模板',
                duration: 3000
            });
            return;
        }

        //物料号非空校验
        if (mrlCode == "" || mrlCode == null || mrlCode == undefined) {
            api.toast({
                msg: '物料号不能为空',
                duration: 3000
            });
            return;
        }

        //批次序列号非空校验
        if (lotCode == "" || lotCode == null || lotCode == undefined) {
            if (serialNo == "" || serialNo == null || serialNo == undefined) {
                api.toast({
                    msg: '批次号和序列号必须录入一个',
                    duration: 3000
                });
                return;
            }
        } else {
            if (serialNo != "" && serialNo != null && serialNo != undefined) {
                api.toast({
                    msg: '批次号和序列号只能录入一个',
                    duration: 3000
                });
                return;
            }
        }

        //数量非空校验
        if (qty == "" || qty == null || qty == undefined) {
            api.toast({
                msg: '请录入检测数量',
                duration: 3000
            });
            return;
        } else {
            if (parseInt(qty) <= 0) {
                api.toast({
                    msg: '检测数量必须大于0',
                    duration: 3000
                });
                return;
            }
        }
        console.log(JSON.stringify(josnList))
        var type = document.getElementById("zxResult").value;
        var taskState = document.getElementById("zxState").value;

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcmChkBillCreateDisposeSave";
        var data = {
            values: {
                un: un,
                chkBillType: '2', //检测单类型
                chkTemplateCode: chkTemplateCode, //检测模板编码
                lotCode: lotCode, // 批次号
                serialNo: serialNo, //序列号
                qty: qty, //检测数量
                workOrderCode: workCenterCode, //产线
                taskId: taskId,
                rowData: JSON.stringify(josnList),
                type: type,
                taskState: taskState,
                mrlCode: mrlCode,//物料编码
                mrlName: mrlName,//物料名称
                mrlGid: mrlGid,//物料ID
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //清空所有信息，重新扫设备选任务
                    $("#chkTemplateCode").val("");
                    $("#chkTemplateName").val("");
                    $("#chkTypeName").val("");
                    $("#mrlCode").val("");
                    $("#mrlName").val("");
                    $("#lotCode").val("");
                    $("#serialNo").val("");
                    // $("#qty").val("");
                    $("#qty").val("1");
                    $("#workCenterCode").val("");
                    $("#opCode").val("");
                    taskId = "";
                    taskCode = "";
                    itemIds = "";
                    itemCodes = "";
                    itemNames = "";
                    itemModes = "";
                    itemValues = "";
                    josnList = [];

                    mrlGids = "";
                    mrlCodes = "";
                    mrlNames = "";
                    mrlExNames = "";
                    qtys = "";
                    measureNames = "";
                    consumeTypes = "";
                    remarks = "";

                    // 清空执行状态					
                    $("#zxState").val("2");
                    // 清空执行结果					
                    $("#zxResult").val("0");
                    // 清空执行时间
                    //清空任务选择
                    $("#chkTaskCode").attr("value", "");
                    //清空点检项表格
                    $("#chkItemTableHead").children().remove();


                    $("#chkBillCodeT").html(myobj.chkBillCodeT);
                    $("#returnType").html("成功");

                    $("#tableDiv").css('display', 'block');

                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
            }
        });
    }

    //序列号扫描回车
    $("#serialNo").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#serialNo").val(tm);
            //拆分序列号
            var arr = tm.split("#");
            //物料号
            $("#mrlCode").val(arr[1]);
            mrlCode = arr[1]
            getMrlName(mrlCode)
            //获取检测模板
            //getChkTemplate(chkType, arr[1])
            getComboxOpCode(chkType, arr[1])
            $("#tableDiv").css('display', 'none');
        }
    });

    //批次号扫描回车
    $("#lotCode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#lotCode").val(tm);
        }
    });

    //产线扫描回车
    $("#workCenterCode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#workCenterCode").val(tm);
        }
    });



    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>